#define MAX_SIZE 10001

typedef struct {
    int* data;
    int t;
    int min;
} MinStack;

MinStack* minStackCreate() {
    MinStack* o = (MinStack*)malloc(sizeof(MinStack));
    o->data = (int*)malloc(sizeof(int) * MAX_SIZE);
    o->t = -1;
    o->min = INT_MAX;
    return o;
}

void minStackPush(MinStack* o, int v) {
    if (o->t >= MAX_SIZE) {
        return;
    }
    o->data[++(o->t)] = v;
    if (v < o->min) {
        o->min = v;
    }
}

void minStackPop(MinStack* o) {
    if (o->t < 0) {
        return;
    }
    o->t--;
    if (o->t >= 0) {
        o->min = o->data[o->t];
    } else {
        o->min = INT_MAX;
    }
    for (int i = o->t; i >= 0; i--) {
        if (o->data[i] < o->min) {
            o->min = o->data[i];
        }
    }
}

int minStackTop(MinStack* o) {
    return o->data[o->t];
}

int minStackGetMin(MinStack* o) {
    if (o->t < 0) {
        return -1;
    }
    return o->min;
}

void minStackFree(MinStack* o) {
    free(o);
}